#define _CRT_SECURE_NO_WARNINGS 1

//https://leetcode.cn/problems/letter-combinations-of-a-phone-number/

class Solution {
    string hash[10] = { "",    "",    "abc",  "def", "ghi",
                       "jkl", "mno", "pqrs", "tuv", "wxyz" };
    vector<string> ret;
    string path;
public:
    vector<string> letterCombinations(string digits) {
        if (digits.size() == 0) return ret;
        dfs(digits, 0);
        return ret;
    }
    void dfs(string digits, int pos)
    {
        if (path.size() == digits.size())
        {
            ret.push_back(path);
            return;
        }
        for (auto& c : hash[digits[pos] - '0'])
        {
            path.push_back(c);
            dfs(digits, pos + 1);
            path.pop_back();
        }
    }
};